package com.bailan.foreat.controller;


import com.bailan.foreat.entity.Order;
import com.bailan.foreat.service.ItemService;
import com.bailan.foreat.vo.OrderIdItemsVo;
import com.bailan.foreat.vo.OrderItemVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.xml.internal.serializer.AttributesImplSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@Controller
@RequestMapping("/item")
public class ItemController {

    @Autowired
    ItemService itemService;

    @RequestMapping("selectItem")
    @ResponseBody
    public Page<OrderIdItemsVo> selectItem(@RequestParam(defaultValue = "1") Integer currentPage,
                                           @RequestParam(defaultValue = "3") Integer pageSize,
                                           Integer storeId){
        Page<OrderIdItemsVo> orderIdItemsVoPage = itemService.selectMyItem(currentPage, pageSize, storeId);
        System.out.println("orderIdItemsVoPage.getRecords():"+orderIdItemsVoPage.getRecords());
        return orderIdItemsVoPage;
    }

    @RequestMapping("updateItemStatus")
    @ResponseBody
    public String updateItemStatus(@RequestBody List<OrderItemVo> orderItemVos){

        System.out.println("...orderItemVos..."+orderItemVos);
        itemService.updateItemStatus(orderItemVos);

//        Integer storeId=(Integer)model.getAttribute("storeId");
//        System.out.println("...storeId..."+storeId);
//        System.out.println("...order..."+order);
        return "ok";
    }

    @RequestMapping("storeId")
    public String storeId(Integer storeId, Model model){
        System.out.println("storeId:"+storeId);
        model.addAttribute("storeId", storeId);
        return "sellerorder";
    }

}

